<?php echo $this->element('displayHeader'); ?>
<div class="toolbar"><?php echo $this->element('toolbar', array('buttons' => array('add', 'search', 'refresh'))); ?></div>

<?php if (empty($this->data)) : // ถ้าไม่มีข้อมูล ?>
    <?php echo $this->element('dataNotFound'); ?>
<? else : // ถ้ามีข้อมูล ?>
    <?php //$paginator->options(array('update' => 'content', 'indicator' => 'indicator')); ?>
    <?php echo $this->element('dataCaptionLimit'); ?>
    <?php $cur = $paginator->counter(array('format' => '%start%')); ?>

    <table class="data">
        <thead>
            <tr>
                <th class="no"><?php echo $paginator->sort('No', 'id'); ?></th>
                <th><?php echo $paginator->sort('Request no.', 'DeRH.request_no'); ?></th>
                <th width="90px"><?php echo $paginator->sort('Request Date', 'DeRH.request_date'); ?></th>
                <th><?php echo $paginator->sort('Vendor', 'Supplier.name'); ?></th>
                <th width="95px"><?php echo $paginator->sort('Request Delivery Date', 'DeRH.due_date'); ?></th>
                <th width="90px"><?php echo $paginator->sort('Actual Delivery Date', 'DeRH.due_date'); ?></th>
                <th><?php echo $paginator->sort('Customer Doc. No.', 'DeRH.custoemr_document_no'); ?></th>
                <th><?php echo $paginator->sort('Status', 'DeRStatus.title'); ?></th>
                <th><?php echo $paginator->sort('End User', 'DeRH.end_user'); ?></th>
                <th><?php echo $paginator->sort('Request by', 'DeRH.request_by'); ?></th>
                <th>Invoiced</th>
                <th class="action">&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->data as $i => $data): ?>
                <tr class="<?php echo (($i + 1) % 2 == 0) ? 'even-cell' : 'odd-cell'; ?>">
                    <td class="center"><?php echo $i + 1; ?></td>
                    <td>
                        <?php
                        echo $data['DeRH']['request_no'];
                        if ($data['DeRH']['is_returned']) {
                            echo $html->link(' ' . ($data['DeRtH']['delivery_return_status_id'] == DeRtStatus::RETURNING ? $html->image('icon/return2.png') : $html->image('icon/return.png')), array('controller' => 'delivery_returns', 'action' => 'view', 'delivery_request_head_id:' . $data['DeRH']['id']), array('target' => '_blank'), null, false);
                        }
                        ?>
                    </td>
                    <td class="center"><?php echo $data['DeRH']['request_date']; ?></td>
                    <td><?php echo $data['Supplier']['name']; ?></td>
                    <td><?php echo $data['DeRH']['due_date']; ?></td>
                    <td><?php echo $data['DeRH']['supplier_due_date']; ?></td>
                    <td><?php echo $data['DeRH']['customer_document_no']; ?></td>
                    <td><?php echo $data['DeRStatus']['title'], ($data['DeRH']['is_partial'] ? ' (Partial)' : ''); ?></td>
                    <td><?php echo $data['DeRH']['end_user']; ?></td>
                    <td><?php echo $data['DeRH']['request_by']; ?></td>
                    <td>
                        <span id="spanInvoiced<?php echo $i; ?>">
                            <?php echo $data['DeRH']['is_invoiced'] == true ? (!empty($data['DeRH']['invoice_no']) ? $data['DeRH']['invoice_no'] : 'Yes') : 'No'; ?>
                        </span>
                    </td>
                    <td><?php echo $html->link($html->image('icon/edit.png', array('title' => 'edit', 'alt' => 'edit')), '/delivery_requests/view/' . $data['DeRH']['id'], null, null, false); ?></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>

    <?php echo $this->element('paging'); ?>
<? endif; ?>
<?php
//debug($this->data); ?>